﻿using System;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;

namespace Kaiser.InversionOfControl.AopProviders
{
    [AttributeUsage(AttributeTargets.Method|AttributeTargets.Class)]
    public class UnityAopAttribute : HandlerAttribute, ICallHandler, IInterceptionBehavior
    {
        public override ICallHandler CreateHandler(IUnityContainer container)
        {
            return this;
        }
      

        public System.Collections.Generic.IEnumerable<Type> GetRequiredInterfaces()
        {
            return Type.EmptyTypes;
        }

        public virtual IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate nextMethod)
        {
            return nextMethod()(input, nextMethod);
        }

        public virtual IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate nextMethod)
        {
            return nextMethod()(input, nextMethod);
        }

        public bool WillExecute
        {
            get { return true; }
        }
    }
}
